// 桥接模式采用组合关系代替继承关系，从而减低了抽象和实现的耦合性
// 优点： 由于抽象与实现分离，扩展性强；实现过程对客户透明
// 缺点： 由于聚合关系建立再抽象层，要求开发者针对抽象化进行设计和编程，增加了系统的理解和设计难度

#include <iostream>
#include <string>


class ImplementorAbstract
{
    public:
    virtual void print() = 0;
    virtual ~ImplementorAbstract(){};

};

class Implementor:public ImplementorAbstract
{
    public:
    virtual ~Implementor(){};
    void print(){
        std::cout<<"This is a implementor class"<<std::endl;
    }

};


class AlgorithmAbstract
{
    public:
    AlgorithmAbstract(){};
    virtual ~AlgorithmAbstract(){};

    virtual void run() = 0;

    protected:
    AlgorithmAbstract(ImplementorAbstract* implementor){
        m_implementor = implementor;
    }
    ImplementorAbstract * m_implementor;

};

class Algorithm:public AlgorithmAbstract
{
    public:
    Algorithm(ImplementorAbstract* implementor):AlgorithmAbstract(implementor){};

    void run(){
        std::cout<<" refined algorithm:"<<std::endl;
        m_implementor->print();
        std::cout<<"run finished."<<std::endl;
    }

};


int main(int argc, char** argv)
{
    ImplementorAbstract* implementor = new Implementor();
    AlgorithmAbstract* algorithm = new Algorithm(implementor);

    algorithm->run();

    delete implementor;
    delete algorithm;
    
    return 0;
}